<#include "/able/_inc/_head.html"/>
<#include "/able/_inc/_layout.html"/>

<!DOCTYPE HTML>
<!--[if IE 8]><html class="ie8" lang="en"><![endif]-->
<!--[if IE 9]><html class="ie9" lang="en"><![endif]-->
<!--[if !IE]><!-->
<html lang="${lang}">

<head>
    <@head />
</head>
<body>
<@layout>
<div class="wrap-content" id="container">
<!-- start: PAGE TITLE -->
<section id="page-title">
    <div class="row">
        <div class="col-sm-8">
            <label>微信 - 公众号设置</label>
        </div>

    </div>
</section>
<!-- end: PAGE TITLE -->
<!-- start: BASIC TABLE -->
<div class="container-fluid container-fullw bg-white">
    <div class="row">
        <div class="col-md-12">
            <div class="alert alert-info">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
                <div><i class="fa fa-question-circle"></i>操作提示</div>
                <ul>
                    <li>该页面展示了商城所有的广告。</li>
                    <li>可搜索广告名称关键词进行查询，侧边栏可进行高级搜索。</li>
                </ul>
            </div>

            <div class="tabbable">
                <ul id="myTab1" class="nav nav-tabs">
                    <li class="active">
                        <a href="#tab-01" data-toggle="tab">
                            公众号设置
                        </a>
                    </li>

                </ul>

                <div class="tab-content">
                    <div class="tab-pane fade in active" id="tab-01">
                        <div class="row">
                            <div class="col-lg-8 col-md-12">
                                <form id="form" role="form" class="form-horizontal"
                                      action="${ctx_admin}<#if model?exists>/wx-account/update<#else>/wx-account/add</#if>"
                                      method="post">
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label" for="name">
                                            公众号名称：<span class="symbol required" aria-required="true"></span>
                                        </label>
                                        <div class="col-sm-7">
                                            <input type="hidden" name="id" value="${model.id}">
                                            <input id="name" name="name" type="text" class="form-control required"
                                                   placeholder="" value="${model.name}">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-3 control-label" for="code">
                                            公众微信号code：<span class="symbol required" aria-required="true"></span>
                                        </label>
                                        <div class="col-sm-7">
                                            <input id="code" name="code" type="text" class="form-control required"
                                                   placeholder="" value="${model.code}">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-3 control-label" for="email">
                                            公众帐号邮箱：<span class="symbol required" aria-required="true"></span>
                                        </label>
                                        <div class="col-sm-7">
                                            <input id="email" name="email" type="text" class="form-control required"
                                                   placeholder="" value="${model.email}">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-3 control-label" for="url">
                                            URL(不需要填写)：<span class="symbol required" aria-required="true"></span>
                                        </label>
                                        <div class="col-sm-7">
                                            <input id="url" name="url" type="text" class="form-control required"
                                                   placeholder="" value="${model.url}">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-3 control-label" for="token">
                                            公众帐号TOKEN：<span class="symbol required" aria-required="true"></span>
                                        </label>
                                        <div class="col-sm-7">
                                            <input id="token" name="token" type="text" class="form-control required"
                                                   placeholder="" value="${model.token}">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-3 control-label" for="token">
                                            公众号类型：<span class="symbol required" aria-required="true"></span>
                                        </label>
                                        <div class="col-sm-7">
                                            <select id="stype" name="stype" size="1" class="form-control required">
                                                <option value="1" <#if model.stype==1>selected="selected"</#if>>服务号
                                                </option>
                                                <option value="2" <#if model.stype==2>selected="selected"</#if>>订阅号
                                                </option>
                                                <option value="3" <#if model.stype==3>selected="selected"</#if>>企业号
                                                </option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-3 control-label" for="appid">
                                            公众帐号APPID：<span class="symbol required" aria-required="true"></span>
                                        </label>
                                        <div class="col-sm-7">
                                            <input id="appid" name="appid" type="text" class="form-control required"
                                                   placeholder="" value="${model.appid}">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-3 control-label" for="appsecret">
                                            公众帐号APPSECRET：<span class="symbol required" aria-required="true"></span>
                                        </label>
                                        <div class="col-sm-7">
                                            <input id="appsecret" name="appsecret" type="text"
                                                   class="form-control required" placeholder=""
                                                   value="${model.appsecret}">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="col-sm-3 control-label" for="description">
                                            公众帐号描述：<span class="symbol required" aria-required="true"></span>
                                        </label>
                                        <div class="col-sm-7">
                                            <textarea id="description" name="description"
                                                      class="form-control">${model.description}</textarea>
                                        </div>
                                    </div>


                                    <div class="form-group margin-bottom-0">
                                        <div class="col-sm-offset-2 col-sm-10">
                                            <button class="btn  btn-primary" type="submit">
                                                确定
                                            </button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>


                </div>
            </div>


        </div>
    </div>
</div>

</@layout>





<script type="text/javascript">

    var FormValidator = function () {
        var formValidator = function () {
            var form = $('#form');
            var errorHandler = $('.errorHandler', form);
            var successHandler = $('.successHandler', form);
            form.validate({
                errorElement: "span", // contain the error msg in a small tag
                errorClass: 'help-block',
                errorPlacement: function (error, element) { // render error placement for each input type
                },
                ignore: "",
                rules: {},
                messages: {},
                invalidHandler: function (event, validator) { //display error alert on form submit
                    successHandler.hide();
                    errorHandler.show();
                },
                highlight: function (element) {
                    $(element).closest('.help-block').removeClass('valid');
                    // display OK icon
                    $(element).closest('.form-group').removeClass('has-success').addClass('has-error').find('.symbol').removeClass('ok').addClass('required');
                    // add the Bootstrap error class to the control group
                },
                unhighlight: function (element) { // revert the change done by hightlight
                    $(element).closest('.form-group').removeClass('has-error');
                    // set error class to the control group
                },
                success: function (label, element) {
                    label.addClass('help-block valid');
                    // mark the current input as valid and display OK icon
                    $(element).closest('.form-group').removeClass('has-error').addClass('has-success').find('.symbol').removeClass('required').addClass('ok');
                },
                submitHandler: function (form) {
                    successHandler.show();
                    errorHandler.hide();
                    $.ajax({
                        type: 'post',
                        url: form.action,
                        async: false, //同步方法，如果用异步的话，flag永远为1
                        dataType: 'json',
                        data: $(form).serialize(),
                        success: function (res) {
                            if (res.success) {
                                layer.msg(res.message, {
                                    icon: 1,
                                    time: 2000, ///2秒关闭（如果不配置，默认是3秒）
                                }, function () {
                                    location.reload();
                                });
                            } else {
                                layer.msg(res.message, {icon: 2});
                            }
                        }
                    });
                }
            });
        };

        return {
            init: function () {
                formValidator();
            }
        };
    }();


    $(function () {
        $("a.preview").preview();
        FormValidator.init();


    });


</script>
